package com.richfit.barcodesystem_cczt.fragments.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;

import com.bigkoo.alertview.AlertView;
import com.richfit.barcodesystem_cczt.databinding.LayoutInformationServiceItemBinding;
import com.richfit.barcodesystem_cczt.fragments.model.InventoriesEntity;

import java.util.List;

public class Information_Adapter extends BaseAdapter {
    private LayoutInformationServiceItemBinding binding;
    private Context mContext;
    private List<InventoriesEntity.RowsBean> list;
    private int mEditTextIndex = -1;

    public Information_Adapter(Context context, List<InventoriesEntity.RowsBean> list) {
        this.mContext = context;
        this.list = list;
    }

    private ItemEditTextListener itemEditTextListener;

    public void setOnItemEditTextListener(ItemEditTextListener itemClickListener) {
        this.itemEditTextListener = itemClickListener;

    }

    public interface ItemEditTextListener {
        void onItemEditText(EditText editText, int position);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public InventoriesEntity.RowsBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        if (view == null) {
            binding = LayoutInformationServiceItemBinding.inflate(LayoutInflater.from(mContext));
            view = binding.getRoot();
            view.setTag(binding);
        } else {
            binding = (LayoutInformationServiceItemBinding) view.getTag();
        }
        InventoriesEntity.RowsBean detail = getItem(position);
        //装箱单号
        binding.TxtBoxNo.setText(detail.getBoxNo());
        //箱号
        binding.TxtZBoxNum.setText(detail.getZboxNum());
        binding.TxtZBoxNum.setOnClickListener(v -> showMsg(detail.getZboxNum()));
        //仓库
        binding.TxtWhName.setText(detail.getWhName());
        binding.TxtWhName.setOnClickListener(v -> showMsg(detail.getWhName()));

        //仓号
        binding.TxtLocation.setText(detail.getLocation());
        binding.TxtLocation.setOnClickListener(v -> showMsg(detail.getLocation()));

        //批次
        binding.TxtBatchNum.setText(detail.getBatchNum());
        binding.TxtBatchNum.setOnClickListener(v -> showMsg(detail.getBatchNum()));

        //库存数量
        binding.TxtAvailableQuantity.setText(detail.getAvailableQuantity() + "");
        return view;
    }

    AlertView alertView;

    void showMsg(String msg) {
        alertView = new AlertView("详细信息", msg, null,
                new String[]{"确定"}, null, mContext,
                AlertView.Style.Alert, (o, position1) -> {
            alertView.dismiss();
        });
        alertView.show();
    }
}
